package com.zxg.zbc.dal.query;

import java.io.Serializable;

public class BasePagerQuery implements Serializable {

  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  private Integer           count;
  private Integer           curPage          = 1;
  private Integer           startRow         = 0;
  private Integer           pageSize         = 20;
  private Integer           pageCount;
  private boolean           hasNext          = true;

  public boolean hasNext() {
    return hasNext;
  }

  public void setHasNext(boolean hasNext) {
    this.hasNext = hasNext;
  }

  public Integer getPageCount() {
    return pageCount;
  }

  public void setPageCount(Integer pageCount) {
    this.pageCount = pageCount;
  }

  public Integer getTotalPage() {
    return pageCount == null ? 0 : pageCount;
  }

  public void setTotalPage(Integer totalPage) {
    this.pageCount = totalPage;
  }

  public Integer getStartRow() {
    return startRow;
  }

  public void setStartRow(Integer startRow) {
    this.startRow = startRow;
  }

  public Integer getCount() {
    return count == null ? 0 : count;
  }

  public void setCount(Integer totalCount) {
    this.count = totalCount;
    int totalPage = this.count / pageSize;
    if (this.count % pageSize != 0)
      totalPage = totalPage + 1;
    this.pageCount = totalPage;
    this.hasNext = this.pageCount > curPage;
  }

  public Integer getCurPage() {
    return curPage == null ? 0 : curPage;
  }

  public Integer getCurPageFrom0() {
    return curPage == null ? 0 : curPage - 1;
  }

  public void setCurPage(Integer page) {
    this.curPage = page;
    this.startRow = page > 0 ? ((page - 1) * pageSize) : 0;
  }

  public Integer getPageSize() {
    return pageSize;
  }

  public void setPageSize(Integer pageSize) {
    this.pageSize = pageSize;
    this.startRow = curPage > 0 ? ((curPage - 1) * pageSize) : 0;
  }

  public Integer nextPage() {
    int next = this.curPage + 1;
    return next > pageCount ? pageCount : next;
  }

  public Integer prePage() {
    int pre = this.curPage - 1;
    return pre < 1 ? 1 : pre;
  }
}
